home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / toolkit.jar / content / global / bindings / button.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-04-13  |  8.3 KB  |  251 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="buttonBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.    xmlns:xbl="http://www.mozilla.org/xbl">
  7.  
  8.   <binding id="button-base" extends="chrome://global/content/bindings/general.xml#basetext">
  9.     <implementation implements="nsIDOMXULButtonElement, nsIAccessibleProvider">
  10.       <property name="accessible">
  11.         <getter>
  12.           <![CDATA[
  13.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  14.             return accService.createXULButtonAccessible(this);
  15.           ]]>
  16.         </getter>
  17.       </property>
  18.  
  19.       <property name="type"
  20.                 onget="return this.getAttribute('type');"
  21.                 onset="this.setAttribute('type', val); return val;"/>
  22.  
  23.       <property name="dlgType"
  24.                 onget="return this.getAttribute('dlgType');"
  25.                 onset="this.setAttribute('dlgType', val); return val;"/>
  26.  
  27.       <property name="group"
  28.                 onget="return this.getAttribute('group');"
  29.                 onset="this.setAttribute('group', val); return val;"/>
  30.  
  31.       <property name="open"
  32.                 onget="return this.hasAttribute('open');"
  33.                 onset="if (val) this.setAttribute('open', 'true');
  34.                        else this.removeAttribute('open'); return val;"/>
  35.  
  36.       <property name="checked" onget="return this.hasAttribute('checked');">
  37.         <setter><![CDATA[
  38.           if (this.type == "checkbox") {
  39.             this.checkState = val ? 1 : 0;
  40.           } else if (this.type == "radio" && val) {
  41.             var sibs = this.parentNode.getElementsByAttribute("group", this.group);
  42.             for (var i = 0; i < sibs.length; ++i)
  43.               if (sibs[i].checked)
  44.                 sibs[i].checked = false;
  45.           }
  46.  
  47.           if (val)
  48.             this.setAttribute("checked", "true");
  49.           else
  50.             this.removeAttribute("checked");
  51.           
  52.           return val;
  53.         ]]></setter>
  54.       </property>
  55.       
  56.       <property name="checkState">
  57.         <getter><![CDATA[
  58.           var state = this.getAttribute("checkState");
  59.           if (state == "")
  60.             return this.checked ? 1 : 0;
  61.           else
  62.             return state == "0" ? 0 : (state == "2" ? 2 : 1);
  63.         ]]></getter>
  64.         <setter><![CDATA[
  65.           this.setAttribute("checkState", val);
  66.           return val;
  67.         ]]></setter>
  68.       </property>
  69.       
  70.       <property name="autoCheck"
  71.                 onget="return this.getAttribute('autoCheck') == 'true';"
  72.                 onset="this.setAttribute('autoCheck', val); return val;"/>
  73.     </implementation>
  74.  
  75.     <handlers>
  76.       <handler event="command">
  77.       <![CDATA[
  78.         if (this.autoCheck || !this.hasAttribute("autoCheck")) {
  79.           if (this.type == "checkbox") {
  80.             this.checked = !this.checked;
  81.           } else if (this.type == "radio") {
  82.             this.checked = true;
  83.           }
  84.         }
  85.       ]]>
  86.       </handler>
  87.  
  88.     </handlers>
  89.   </binding>
  90.  
  91.   <binding id="button" display="xul:button"
  92.            extends="chrome://global/content/bindings/button.xml#button-base">
  93.     <resources>
  94.       <stylesheet src="chrome://global/skin/button.css"/>
  95.     </resources>
  96.  
  97.     <content>
  98.       <children includes="observes|template|menupopup|tooltip"/>
  99.       <xul:hbox class="box-inherit button-box" xbl:inherits="align,dir,pack,orient"
  100.                 align="center" pack="center" flex="1">
  101.         <children>
  102.           <xul:image class="button-icon" xbl:inherits="src=image"/>
  103.           <xul:label class="button-text" xbl:inherits="value=label,accesskey,crop" flex="1"/>
  104.         </children>
  105.       </xul:hbox>
  106.     </content>
  107.   </binding>
  108.  
  109.   <binding id="menu" display="xul:menu"
  110.            extends="chrome://global/content/bindings/button.xml#button">
  111.     <content>
  112.       <children includes="observes|template|menupopup|tooltip"/>
  113.       <xul:hbox class="box-inherit button-box" xbl:inherits="align,dir,pack,orient"
  114.                 align="center" pack="center" flex="1">
  115.         <children>
  116.           <xul:image class="button-icon" xbl:inherits="src=image"/>
  117.           <xul:label class="button-text" xbl:inherits="value=label,accesskey,crop" flex="1"/>
  118.           <xul:dropmarker class="button-menu-dropmarker" xbl:inherits="open,disabled"/>
  119.         </children>
  120.       </xul:hbox>
  121.     </content>
  122.   </binding>           
  123.  
  124.   <binding id="menu-button-base"
  125.            extends="chrome://global/content/bindings/button.xml#button-base">
  126.     <implementation>
  127.       <constructor>
  128.         this.init();
  129.       </constructor>
  130.       
  131.       <method name="init">
  132.         <body>
  133.         <![CDATA[
  134.           var btn = document.getAnonymousElementByAttribute(this, "anonid", "button");
  135.           if (!btn)
  136.             throw "XBL binding for <button type=\"menu-button\"/> binding must contain an element with anonid=\"button\"";
  137.           
  138.           btn._menubuttonParent = this;
  139.           btn.addEventListener("mouseover", function() { 
  140.             if (!this.disabled)
  141.               this._menubuttonParent.buttonover = true; 
  142.           }, true);
  143.           btn.addEventListener("mouseout", function() {
  144.             this._menubuttonParent.buttonover = false;
  145.            }, true);
  146.           btn.addEventListener("mousedown", function() {
  147.             if (!this.disabled) {
  148.               this._menubuttonParent.buttondown = true;
  149.               this._menubuttonParent._captureMouseUp();
  150.             }
  151.           }, true);
  152.         ]]>
  153.         </body>
  154.       </method>
  155.       
  156.       <property name="buttonover" onget="return this.getAttribute('buttonover');">
  157.         <setter>
  158.         <![CDATA[
  159.           var v = val || val == "true";
  160.           if (!v && this.buttondown) { 
  161.             this.buttondown = false;
  162.             this._pendingActive = true;
  163.           } 
  164.           else {
  165.             if (this._pendingActive) {
  166.               this.buttondown = true;
  167.               this._pendingActive = false;
  168.             }
  169.           }
  170.  
  171.           if (v)
  172.             this.setAttribute("buttonover", "true");
  173.           else
  174.             this.removeAttribute("buttonover");
  175.           return val;
  176.         ]]>
  177.         </setter>
  178.       </property>
  179.       
  180.       <property name="buttondown" onget="return this.getAttribute('buttondown') == 'true';">
  181.         <setter>
  182.         <![CDATA[
  183.           if (val || val == "true")
  184.             this.setAttribute("buttondown", "true");
  185.           else
  186.             this.removeAttribute("buttondown");
  187.           return val;
  188.         ]]>
  189.         </setter>
  190.       </property>
  191.       
  192.       <field name="_pendingActive">false</field>
  193.  
  194.       <method name="_captureMouseUp">
  195.         <body>
  196.         <![CDATA[
  197.           document.__ButtonMenuMouseDown__ = this;
  198.           document.addEventListener("mouseup", this._onGlobalMouseUp, true);
  199.         ]]>
  200.         </body>
  201.       </method>
  202.  
  203.       <method name="_onGlobalMouseUp" readonly="true">
  204.         <body>
  205.         <![CDATA[
  206.           var btn = document.__ButtonMenuMouseDown__;
  207.           btn._onMouseReallyUp();
  208.           document.removeEventListener("mouseup", btn._onGlobalMouseUp, true);
  209.           delete document.__ButtonMenuMouseDown__;
  210.         ]]>
  211.         </body>
  212.       </method>
  213.  
  214.       <method name="_onMouseReallyUp">
  215.         <body>
  216.         <![CDATA[
  217.           this._pendingActive = false;
  218.           this.buttondown = false;
  219.         ]]>
  220.         </body>
  221.       </method>
  222.  
  223.     </implementation>
  224.   </binding>
  225.  
  226.   <binding id="menu-button" display="xul:menu"
  227.            extends="chrome://global/content/bindings/button.xml#menu-button-base">
  228.     <resources>
  229.       <stylesheet src="chrome://global/skin/button.css"/>
  230.     </resources>
  231.  
  232.     <content>
  233.       <children includes="observes|template|menupopup|tooltip"/>
  234.       <xul:button class="box-inherit button-menubutton-button"
  235.                   anonid="button" flex="1" allowevents="true"
  236.                   xbl:inherits="disabled,crop,image,label,accessKey,command,
  237.                                 buttonover,buttondown,align,dir,pack,orient">
  238.         <children/>
  239.       </xul:button>
  240.       <xul:dropmarker class="button-menubutton-dropmarker" xbl:inherits="open,disabled"/>
  241.     </content>
  242.   </binding>
  243.   
  244.   <binding id="button-image" display="xul:button"
  245.            extends="chrome://global/content/bindings/button.xml#button">
  246.     <content>
  247.       <xul:image class="button-image-icon" xbl:inherits="src=image"/>
  248.     </content>
  249.   </binding>
  250.   
  251. </bindings>